package com.foxchen.ddns.service.impl.v4;

import cn.hutool.http.HttpUtil;
import com.foxchen.ddns.service.IpGetServiceV4;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component("https://2024.ip138.com")
public class Ip138ServiceImpl implements IpGetServiceV4 {

    @Override
    public String getIp(String url) {
        String searchIpRes = HttpUtil.get(url,3000);
        Pattern p = Pattern.compile("<title>(.*?)</title>");
        Matcher m = p.matcher(searchIpRes);
        if (m.find()) {
            return m.group(1).replace("您的IP地址是：","");
        }

        return StringUtils.EMPTY;
    }
}
